**********************************************************
* Describe basic demographic/economic and unrest dataset *
**********************************************************
set more off
set scheme s2mono
use Thomson_2018_GDR_Data.dta, clear

***************************************
* Histograms of variables of interest *
***************************************
hist unrest, bin(9) graphregion(color(white)) bgcolor(white) fcolor(gs13) lcolor(black) lwidth(medthick)
graph save hist_unrest, replace

hist ag_wc_total, graphregion(color(white)) bgcolor(white) fcolor(gs13) lcolor(black) lwidth(medthick)
graph save hist_indfarmers, replace

hist bomb_dest_all if bomb_dest_all<0.8, graphregion(color(white)) bgcolor(white) fcolor(gs13) lcolor(black) lwidth(medthick)
graph save hist_bombdest, replace

hist cons_total, graphregion(color(white)) bgcolor(white) fcolor(gs13) lcolor(black) lwidth(medthick)
graph save hist_cons, replace

hist ln_pop_density, graphregion(color(white)) bgcolor(white) fcolor(gs13) lcolor(black) lwidth(medthick)
graph save hist_popdens, replace

hist living_space, graphregion(color(white)) bgcolor(white) fcolor(gs13) lcolor(black) lwidth(medthick)
graph save hist_livingspace, replace

graph combine hist_unrest.gph hist_cons.gph hist_indfarmers.gph hist_livingspace.gph hist_bombdest.gph hist_popdens.gph, ///
cols(2) xsize(5) ysize(6) graphregion(color(white))
*graph export Var_Hists.pdf, replace



************************************************
* Make tables of unrest and correlation matrix *
************************************************
*latab bez_nr unrest, tf("Unrest_Bezirk_Tab") replace 

*latab stadt unrest, tf("Unrest_Stadt_Tab") replace

pwcorr unrest ag_wc_total living_space bomb_dest_all cons_total if bomb_dest_all<0.80

*corrtex unrest ag_wc_total living_space bomb_dest_all cons_total if bomb_dest_all<0.80, ///
*file("Corr_Tab") replace ///
*title("Correlation Table, 1952 GDR") key(tab:crosstab) dig(2)


graph twoway (scatter unrest bomb_dest_all) (lfit unrest bomb_dest_all)
*extremes bomb_dest_all
reg unrest bomb_dest_all
lvr2plot, mlabel(kreis)

*Leverage plot
reg unrest bomb_dest_all 
lvr2plot, mlabel(kreis)
*graph export "Leverage.pdf"

*sutex bin_unrest mobiliz unrest ag_wc_total living_space bomb_dest_all cons_total bc_total unemp_m ag_bc_total ///
*ln_pop_density bulge_15_25 brd_border w_berlin_border e_berlin_border ///
*if bomb_dest_all<0.8, /// 
*file ("Varstats_Tab") ///
*labels minmax title("Summary Statistics, 1950-53 GDR Data") key(tab:summarystats) replace


****************
* Scatterplots *
****************
graph twoway (scatter unrest ln_pop_density, msymbol(Oh)) ///
	(lfit unrest ln_pop_density, lpattern(solid) lwidth(medthick)) ///
	, ytitle("Unrest") title("Pop Dens") legend(off) xsize(4) ysize(4) graphregion(color(white)) bgcolor(white)
graph save scatter_popdens, replace

graph twoway (scatter unrest living_space, msymbol(Oh)) (lfit unrest living_space, lpattern(solid) lwidth(medthick)) ///
	, ytitle("Unrest") title("Living Space") legend(off) xsize(4) ysize(4) graphregion(color(white)) bgcolor(white)
graph save scatter_livingspace, replace

graph twoway (scatter unrest bomb_dest_all if bomb_dest_all<0.8, msymbol(Oh)) ///
(lfit unrest bomb_dest_all if bomb_dest_all<0.8, lpattern(solid) lwidth(medthick)) ///
	, ytitle("Unrest") title("Bomb Dest") legend(off) xsize(4) ysize(4) graphregion(color(white)) bgcolor(white) 
graph save scatter_bombdest, replace

graph twoway (scatter unrest ag_wc_total, msymbol(Oh)) (lfit unrest ag_wc_total, lpattern(solid) lwidth(medthick)) ///
	, ytitle("Unrest") title("Ind Farmers") legend(off) xsize(4) ysize(4) graphregion(color(white)) bgcolor(white)
graph save scatter_indfarmers, replace

graph twoway (scatter unrest cons_total, msymbol(Oh)) (lfit unrest cons_total, lpattern(solid) lwidth(medthick)) ///
	, ytitle("Unrest") title("Construction") legend(off) xsize(4) ysize(4) graphregion(color(white)) bgcolor(white)
graph save scatter_cons, replace

graph twoway (scatter unrest bc_total, msymbol(Oh)) (lfit unrest bc_total, lpattern(solid) lwidth(medthick)) ///
	, ytitle("Unrest") title("BC Workers") legend(off) xsize(4) ysize(4) graphregion(color(white)) bgcolor(white)
graph save scatter_bc, replace

graph combine scatter_indfarmers.gph scatter_livingspace.gph scatter_bombdest.gph scatter_cons.gph scatter_bc.gph scatter_popdens.gph, ///
cols(2) xsize(5) ysize(6) graphregion(color(white))


****************
* Logit Models *
****************
* Ind Farmers
logit bin_unrest ag_wc_total ln_pop_density ///
bulge_15_25 brd_border w_berlin_border if bomb_dest_all<0.80, robust
est store logit_indfarmers
margins, at(ag_wc_total=(0(0.02)0.16))
marginsplot,  recast(line) recastci(rline) ciopts(lwidth(medthin) lpattern(longdash)) ///
addplot(kdensity ag_wc_total if ag_wc_total>=0 & ag_wc_total<=0.16, yaxis(2)) graphregion(color(white)) xsize(5) ysize(6) ///
title("Ind Farmers") ytitle("Pr(Unrest)") legend(off) xlabel(0(0.02)0.16) ylabel(0(0.1)1)
graph save logit_indfarmers, replace

* Living Space
logit bin_unrest living_space ag_wc_total cons_total ln_pop_density ///
bulge_15_25 brd_border w_berlin_border if bomb_dest_all<0.80, robust
est store logit_livingspace
margins, at(living_space=(7(1)13))
marginsplot,  recast(line) recastci(rline) ciopts(lwidth(medthin) lpattern(longdash)) ///
addplot(kdensity living_space if living_space>=7 & living_space<=13, yaxis(2)) graphregion(color(white)) xsize(5) ysize(6) ///
title("Living Space") ytitle("Pr(Unrest)") legend(off) xlabel(7(0.5)13) ylabel(0(0.1)1)
graph save logit_livingspace, replace

* Bomb Destruction
logit bin_unrest bomb_dest_all ag_wc_total cons_total ln_pop_density ///
bulge_15_25 brd_border w_berlin_border if bomb_dest_all<0.80, robust
est store logit_bombdest
margins, at(bomb_dest_all=(0(0.1)0.6))
marginsplot,  recast(line) recastci(rline) ciopts(lwidth(medthin) lpattern(longdash)) ///
addplot(kdensity bomb_dest_all if e(sample), yaxis(2)) graphregion(color(white)) xsize(5) ysize(6) ///
title("Bomb Destruction") ytitle("Pr(Unrest)") legend(off) xlabel(0(0.1)0.6) ylabel(0(0.1)1)
graph save logit_bombdest, replace

logit bin_unrest bomb_dest ag_wc_total cons_total ln_pop_density ///
bulge_15_25 brd_border if bomb_dest_all<0.80, robust
est store logit_bombdest2
margins, at(bomb_dest=(0(0.1)0.6))
marginsplot

* Construction
logit bin_unrest ag_wc_total cons_total ln_pop_density ///
bulge_15_25 brd_border w_berlin_border if bomb_dest_all<0.80, robust
est store logit_cons
margins, at(cons_total=(0.01(0.01)0.09))
marginsplot,  recast(line) recastci(rline) ciopts(lwidth(medthin) lpattern(longdash)) ///
addplot(kdensity cons_total if cons_total>0.01 & cons_total<0.09, yaxis(2)) graphregion(color(white)) xsize(5) ysize(6) ///
title("Construction") ytitle("Pr(Unrest)") legend(off) ylabel(0(0.1)1)
graph save logit_cons, replace

* Working Class
logit bin_unrest bc_total ag_wc_total cons_total ln_pop_density ///
bulge_15_25 brd_border w_berlin_border if bomb_dest_all<0.80, robust
est store logit_bc
margins, at(bc_total=(0.05(0.05)0.85))
marginsplot,  recast(line) recastci(rline) ciopts(lwidth(medthin) lpattern(longdash)) ///
addplot(kdensity bc_total if e(sample), yaxis(2)) graphregion(color(white)) xsize(5) ysize(6) ///
title("Working Class") ytitle("Pr(Unrest)") legend(off) xlabel(0.05(0.1)0.85) ylabel(0(0.1)1)
graph save logit_bc, replace

* Pop Density
logit bin_unrest ag_wc_total cons_total ln_pop_density ///
bulge_15_25 brd_border w_berlin_border 	if bomb_dest_all<0.80, robust
est store logit_popdens
margins, at(ln_pop_density=(4(0.5)8))
marginsplot,  recast(line) recastci(rline) ciopts(lwidth(medthin) lpattern(longdash)) ///
addplot(kdensity ln_pop_density if ln_pop_density>4 & ln_pop_density<8.01, yaxis(2)) graphregion(color(white)) xsize(5) ysize(6) ///
title("Pop Density") ytitle("Pr(Unrest)") legend(off) xlabel(3.5(0.5)8) ylabel(0(0.1)1)
graph save logit_popdens, replace
margins, at(ln_pop_dens=0.372)

graph combine logit_indfarmers.gph logit_livingspace.gph logit_bombdest.gph logit_cons.gph logit_bc.gph logit_popdens.gph, ///
cols(2) xsize(5) ysize(6) graphregion(color(white))

* Unemployment
logit bin_unrest ln_pop_density ag_wc_total cons_total unemp_m ag_bc_total ///
bulge_15_25 brd_border w_berlin_border if bomb_dest_all<0.80, robust
est store logit_unemp
margins, at(unemp_m=(0.08(0.01)0.12))

***********
* Table 2 *
***********
esttab logit_indfarmers logit_cons logit_livingspace logit_bombdest logit_bombdest2 logit_bc logit_unemp, ///
order(ag_wc_total cons_total living_space bomb_dest_all bomb_dest bc_total unemp_m ag_bc_total ln_pop_density ///
bulge_15_25 brd_border w_berlin_border _cons) ///
keep(cons_total bc_total ag_wc_total living_space bomb_dest_all bomb_dest unemp_m ag_bc_total ln_pop_density ///
bulge_15_25 brd_border w_berlin_border _cons) ///
mtitle("Farmers" "Constr" "Liv Sp" "Bomb Dest" "BD (Cities)" "Working Cl" "Unemp") ///
l nogaps compress b(a2) aic se star(* 0.10 ** 0.05 *** 0.01) type constant
	

*****************
* Ordered Logit *
*****************

* Working Class
ologit mobiliz bc_total ag_wc_total cons_total ln_pop_density ///
bulge_15_25 brd_border w_berlin_border e_berlin_border if bomb_dest_all<0.80, robust
est store ologit_bc
margins, at(bc_total=(0.05(0.05)0.85))
marginsplot,  graphregion(color(white)) xsize(5) ysize(6) ///
title("Working Class") legend(order(5 "Calm" 6 "Assembly" 7 "Strike" 8 "Demo")) xlabel(0.05(0.1)0.85)
graph save ologit_bc, replace

* Ind Farmers / Construction
ologit mobiliz ag_wc_total cons_total ln_pop_density ///
bulge_15_25 brd_border w_berlin_border e_berlin_border if bomb_dest_all<0.80, robust
est store ologit_indfarmers
margins, at(ag_wc_total=(0(0.02)0.16))
marginsplot,  graphregion(color(white)) xsize(5) ysize(6) ///
title("Ind Farmers") legend(order(5 "Calm" 6 "Assembly" 7 "Strike" 8 "Demo")) xlabel(0(0.02)0.16)
graph save ologit_indfarmers, replace

margins, at(cons_total=(0.01(0.01)0.09))
marginsplot, ///
graphregion(color(white)) xsize(5) ysize(6) ///
title("Construction") legend(order(5 "Calm" 6 "Assembly" 7 "Strike" 8 "Demo"))
graph save ologit_cons, replace

* Living Space
ologit mobiliz living_space ag_wc_total cons_total ln_pop_density ///
bulge_15_25 brd_border w_berlin_border e_berlin_border if bomb_dest_all<0.80, robust
est store ologit_livingspace
margins, at(living_space=(7(1)13))
marginsplot,  graphregion(color(white)) xsize(5) ysize(6) ///
title("Living Space") legend(order(5 "Calm" 6 "Assembly" 7 "Strike" 8 "Demo")) xlabel(7(0.5)13)
graph save ologit_livingspace, replace

* Bomb Destruction
ologit mobiliz bomb_dest_all ag_wc_total cons_total ln_pop_density ///
bulge_15_25 brd_border w_berlin_border e_berlin_border if bomb_dest_all<0.80, robust
est store ologit_bombdest
margins, at(bomb_dest_all=(0(0.1)0.6))
marginsplot, graphregion(color(white)) xsize(5) ysize(6) ///
title("Bomb Destruction") legend(order(5 "Calm" 6 "Assembly" 7 "Strike" 8 "Demo")) xlabel(0(0.1)0.6)
graph save ologit_bombdest, replace

* Population Density
ologit mobiliz ln_pop_density ///
bulge_15_25 brd_border w_berlin_border e_berlin_border if bomb_dest_all<0.80, robust
est store ologit_popdens
margins, at(ln_pop_density=(4(0.5)8))
marginsplot, graphregion(color(white)) xsize(5) ysize(6) ///
title("Pop Density") legend(order(5 "Calm" 6 "Assembly" 7 "Strike" 8 "Demo")) xlabel(3.5(0.5)8)
graph save ologit_popdens, replace

grc1leg ologit_indfarmers.gph ologit_cons.gph, ///
cols(2) xsize(4) ysize(7.5) ycommon graphregion(color(white))

esttab ologit_indfarmers ologit_livingspace ologit_bombdest ologit_bc, ///
order(ag_wc_total cons_total living_space bomb_dest_all bc_total ln_pop_density ///
bulge_15_25 brd_border w_berlin_border e_berlin_border) ///
keep(cons_total bc_total ag_wc_total living_space bomb_dest_all ln_pop_density ///
bulge_15_25 brd_border w_berlin_border e_berlin_border) ///
mtitle("Farmers/Constr" "Liv Sp" "Bomb Dest" "Working Cl") ///
l nogaps compress b(a2) aic se star(* 0.10 ** 0.05 *** 0.01) type constant


***********************
* With Region Dummies *
***********************
logit bin_unrest ln_pop_density ///
bulge_15_25 brd_border w_berlin_border e_berlin_border i.bez if bomb_dest_all<0.80
est store logit_popdens

logit bin_unrest cons_total ln_pop_density ///
bulge_15_25 brd_border w_berlin_border e_berlin_border i.bez if bomb_dest_all<0.80
est store logit_cons

logit bin_unrest bomb_dest_all ag_wc_total cons_total ln_pop_density ///
bulge_15_25 brd_border w_berlin_border e_berlin_border i.bez if bomb_dest_all<0.80
est store logit_bombdest

logit bin_unrest bc_total ag_wc_total cons_total ln_pop_density ///
bulge_15_25 brd_border w_berlin_border e_berlin_border i.bez if bomb_dest_all<0.80
est store logit_bc

logit bin_unrest living_space ag_wc_total cons_total ln_pop_density ///
bulge_15_25 brd_border w_berlin_border e_berlin_border i.bez if bomb_dest_all<0.80
est store logit_livingspace

logit bin_unrest ag_wc_total cons_total ln_pop_density ///
bulge_15_25 brd_border w_berlin_border e_berlin_border i.bez if bomb_dest_all<0.80
est store logit_indfarmers

esttab logit_popdens logit_cons logit_indfarmers logit_livingspace logit_bombdest logit_bc, ///
order(cons_total ag_wc_total bc_total living_space bomb_dest_all ln_pop_density ///
bulge_15_25 brd_border w_berlin_border e_berlin_border) ///
keep(cons_total ag_wc_total bc_total living_space bomb_dest_all ln_pop_density ///
bulge_15_25 brd_border w_berlin_border e_berlin_border) ///
l nogaps compress b(a2) aic se star(* 0.10 ** 0.05 *** 0.01) type


*** Spatial Analysis Begins Here! ***

*******************
* Get in GIS Data *
*******************
cd "../GIS Shapefile Germany 1952"
shp2dta using GDR52, database(GDRdb) coordinates(GDRcoord) genid(id) gencentroids(centr) replace
use GDRdb, clear
describe
spmap using GDRcoord, id(id)
destring KREIS_KENN, replace
sort KREIS_KENN
save GDRdb, replace
use "../1952_Bezirke_Kreise/GDR_1952_Data.dta", clear
rename KREIS_KENNC20 KREIS_KENN
sort KREIS_KENN
merge 1:1 KREIS_KENN using GDRdb
drop _merge
replace unrest = 9 if GEN=="Berlin Ost"
replace pop_86= 1223309 if GEN=="Berlin Ost"
replace sum_stasi= 2048 if GEN=="Berlin Ost"
replace GEN = "Berlin" if GEN=="Berlin Ost"

*****************
* Map of Unrest *
*****************
spmap using GDRcoord, id(id)

spmap unrest using GDRcoord, clmethod(custom) clbreaks(0 1 2 4 7 8 10) id(id) fcolor(Oranges) legtitle("Legend") legend(pos(2)) title("Unrest, 17 June 1953")
/// label(label(GEN) xcoord(x_centr) ycoord(y_centr) select(keep if unrest>7 & stadt==1 | id==36) ///
/// size(vlarge) gap(0) position(8))
*graph save unrestmap, replace
*graph export "Unrest_Map.pdf", replace


*************
* 1953 Maps *
*************
spmap ln_pop_density using GDRcoord, id(id) fcolor(Blues) legenda(off) title("Pop. Density")
graph save popdensmap, replace
*graph export "Popdensity_Map.pdf", replace

spmap ag_wc_total using GDRcoord, id(id) fcolor(Greens) legenda(off) title("Ind. Farmers")
graph save indfarmmap, replace
*graph export "Ind_Farmers_Map.pdf", replace

spmap cons_total using GDRcoord, id(id) fcolor(Purples) legenda(off) title("Construction Workers")
graph save constrmap, replace
*graph export "Const_Workers_Map.pdf", replace

spmap bc_total using GDRcoord, id(id) fcolor(Purples) legenda(off) title("Construction Workers")
graph save bcmap, replace
*graph export "BC_Map.pdf", replace


drop if bomb_dest_all==.
spmap bomb_dest_all using GDRcoord, id(id) fcolor(Reds) clmethod(custom) legend(pos(2)) clbreaks(0 0.005 .05 .10 .20 .30 .40 .50 .60 1.00) title("Housing Destroyed %")
graph save bombdestmap, replace
*graph export "Bomb_Destruction_Map.pdf", replace

graph combine unrestmap.gph indfarmmap.gph bombdestmap.gph constrmap.gph


****************************************************************************************************************
* Spatial Regressions - note I have to drop observations where data is missing & outliers to get models to run *
****************************************************************************************************************
drop if id==171 | id==137 | id==116 | id==36 | id==82
drop if bomb_dest_all>0.80
spmat contiguity idmat_c using GDRcoord, id(id) replace normalize(minmax)
spmat summarize idmat_c
spmat graph idmat_c

* Independent Farmers
spreg gs2sls unrest ag_wc_total ln_pop_density ///
bulge_15_25 brd_border w_berlin_border e_berlin_border if bomb_dest_all<0.80, id(id) dlmat(idmat_c) elmat(idmat_c)
est store spreg_indfarmers
margins, at(ag_wc_total=(0(0.02)0.16))
marginsplot,  recast(line) recastci(rline) ciopts(lwidth(medthin) lpattern(longdash)) yline(0, lwidth(thin)) ///
addplot(kdensity ag_wc_total if ag_wc_total>=0 & ag_wc_total<=0.16, yaxis(2)) graphregion(color(white)) xsize(5) ysize(6) ///
title("Ind Farmers") ytitle("Unrest") legend(off) xlabel(0(0.02)0.16) ylabel(0(0.1)1)
graph save spreg_indfarmers, replace

spreg gs2sls mobiliz ag_wc_total ln_pop_density ///
bulge_15_25 brd_border w_berlin_border e_berlin_border if bomb_dest_all<0.80, id(id) dlmat(idmat_c) elmat(idmat_c)
est store spmobiliz_indfarmers

* Construction
spreg gs2sls unrest cons_total ag_wc_total ln_pop_density ///
bulge_15_25 brd_border w_berlin_border e_berlin_border if bomb_dest_all<0.80, id(id) dlmat(idmat_c) elmat(idmat_c)
est store spreg_cons
margins, at(cons_total=(0.01(0.01)0.09))
marginsplot,  recast(line) recastci(rline) ciopts(lwidth(medthin) lpattern(longdash)) yline(0, lwidth(thin)) ///
addplot(kdensity cons_total if cons_total>0.01 & cons_total<0.09, yaxis(2)) graphregion(color(white)) xsize(5) ysize(6) ///
title("Construction") ytitle("Unrest") legend(off) ylabel(0(0.1)1)
graph save spreg_cons, replace

spreg gs2sls mobiliz cons_total ag_wc_total ln_pop_density ///
bulge_15_25 brd_border w_berlin_border e_berlin_border if bomb_dest_all<0.80, id(id) dlmat(idmat_c) elmat(idmat_c)
est store spmobiliz_cons

* Pop Density Graph
margins, at(ln_pop_density=(4(0.5)8))
marginsplot,  recast(line) recastci(rline) ciopts(lwidth(medthin) lpattern(longdash)) yline(0, lwidth(thin)) ///
addplot(kdensity ln_pop_density if ln_pop_density>4 & ln_pop_density<8.01, yaxis(2)) graphregion(color(white)) xsize(5) ysize(6) ///
title("Pop Density") ytitle("Unrest") legend(off) xlabel(3.5(0.5)8) ylabel(0(0.1)1)
graph save spreg_popdens, replace
margins, at(ln_pop_dens=0.372)


* Bomb Destruction
spreg gs2sls unrest bomb_dest_all ag_wc_total cons_total ln_pop_density ///
bulge_15_25 brd_border w_berlin_border e_berlin_border if bomb_dest_all<0.80, id(id) dlmat(idmat_c) elmat(idmat_c)
est store spreg_bombdest
margins, at(bomb_dest_all=(0(0.1)0.6))
marginsplot,  recast(line) recastci(rline) ciopts(lwidth(medthin) lpattern(longdash)) yline(0, lwidth(thin)) ///
addplot(kdensity bomb_dest_all if e(sample), yaxis(2)) graphregion(color(white)) xsize(5) ysize(6) ///
title("Bomb Destruction") ytitle("Unrest") legend(off) xlabel(0(0.1)0.6) ylabel(0(0.1)1)
graph save spreg_bombdest, replace

spreg gs2sls mobiliz bomb_dest_all ag_wc_total cons_total ln_pop_density ///
bulge_15_25 brd_border w_berlin_border e_berlin_border if bomb_dest_all<0.80, id(id) dlmat(idmat_c) elmat(idmat_c)
est store spmobiliz_bombdest

* Working Class
spreg gs2sls unrest bc_total ag_wc_total cons_total ln_pop_density ///
bulge_15_25 brd_border w_berlin_border e_berlin_border if bomb_dest_all<0.80, id(id) dlmat(idmat_c) elmat(idmat_c)
est store spreg_bc
margins, at(bc_total=(0.05(0.05)0.85))
marginsplot,  recast(line) recastci(rline) ciopts(lwidth(medthin) lpattern(longdash)) yline(0, lwidth(thin)) ///
addplot(kdensity bc_total if e(sample), yaxis(2)) graphregion(color(white)) xsize(5) ysize(6) ///
title("Working Class") ytitle("Unrest") legend(off) xlabel(0.05(0.1)0.85) ylabel(0(0.1)1)
graph save spreg_bc, replace

spreg gs2sls mobiliz bc_total ag_wc_total cons_total ln_pop_density ///
bulge_15_25 brd_border w_berlin_border e_berlin_border if bomb_dest_all<0.80, id(id) dlmat(idmat_c) elmat(idmat_c)
est store spmobiliz_bc


* Living space has to be run separately as it has missing values
cd "../GIS Shapefile Germany 1952" 
shp2dta using GDR52, database(GDRdb) coordinates(GDRcoord) genid(id) gencentroids(centr) replace
use GDRdb, clear
describe
spmap using GDRcoord, id(id)
destring KREIS_KENN, replace
sort KREIS_KENN
save GDRdb, replace
use "../1952_Bezirke_Kreise/GDR_1952_Data.dta", clear
rename KREIS_KENNC20 KREIS_KENN
sort KREIS_KENN
merge 1:1 KREIS_KENN using GDRdb
drop _merge
replace unrest = 9 if GEN=="Berlin Ost"
replace pop_86= 1223309 if GEN=="Berlin Ost"
replace sum_stasi= 2048 if GEN=="Berlin Ost"
replace GEN = "Berlin" if GEN=="Berlin Ost"

drop if id==171 | id==137 | id==116 | id==36 | id==82
drop if living_space==.
drop if bomb_dest_all>0.80
spmat contiguity idmat_c using GDRcoord, id(id) replace normalize(minmax)
spmat summarize idmat_c
spmat graph idmat_c

spreg gs2sls unrest living_space ag_wc_total cons_total ln_pop_density ///
bulge_15_25 brd_border w_berlin_border e_berlin_border if bomb_dest_all<0.80, id(id) dlmat(idmat_c) elmat(idmat_c)
est store spreg_livingspace
margins, at(living_space=(7(1)13))
marginsplot,  recast(line) recastci(rline) ciopts(lwidth(medthin) lpattern(longdash)) yline(0, lwidth(thin)) ///
addplot(kdensity living_space if living_space>=7 & living_space<=13, yaxis(2)) graphregion(color(white)) xsize(5) ysize(6) ///
title("Living Space") ytitle("Unrest") legend(off) xlabel(7(0.5)13) ylabel(0(0.1)1)
graph save spreg_livingspace, replace

spreg gs2sls mobiliz living_space ag_wc_total cons_total ln_pop_density ///
bulge_15_25 brd_border w_berlin_border e_berlin_border if bomb_dest_all<0.80, id(id) dlmat(idmat_c) elmat(idmat_c)
est store spmobiliz_livingspace

graph combine spreg_indfarmers.gph spreg_livingspace.gph spreg_bombdest.gph spreg_cons.gph spreg_bc.gph spreg_popdens.gph, ///
cols(2) xsize(5) ysize(6) graphregion(color(white))
graph save GDR_Spregs, replace

***********
* Table 3 *
***********
esttab spreg_indfarmers spreg_cons spreg_livingspace spreg_bombdest spreg_bc, ///
order(ag_wc_total cons_total living_space bomb_dest_all bc_total ln_pop_density ///
bulge_15_25 brd_border w_berlin_border _cons) ///
mtitle("Farmers" "Constr" "Liv Sp" "Bomb Dest" "Working Cl")  ///
l nogaps compress b(a2) se star(* 0.10 ** 0.05 *** 0.01) type


* With Mobilization as dependent variable
esttab spmobiliz_indfarmers spmobiliz_cons spmobiliz_livingspace spmobiliz_bombdest spmobiliz_bc, ///
order(ag_wc_total cons_total living_space bomb_dest_all bc_total ln_pop_density ///
bulge_15_25 brd_border w_berlin_border _cons) ///
mtitle("Farmers" "Constr" "Liv Sp" "Bomb Dest" "Working Cl")  ///
l nogaps compress b(a2) se star(* 0.10 ** 0.05 *** 0.01) type
